import FileSaver from "file-saver";
import XLSX from "xlsx";

export function exportExcel(tid, tname) {
  var xlsxParam = { raw: true }; // the exported content is only parsed, no format conversion
  var wb = XLSX.utils.table_to_book(document.querySelector(tid), xlsxParam);

  /* get binary string as output */
  var wbout = XLSX.write(wb, {
    bookType: "xlsx",
    bookSST: true,
    type: "array",
  });
  try {
    FileSaver.saveAs(
      new Blob([wbout], { type: "application/octet-stream" }),
      (tname || tid) + ".xlsx"
    );
  } catch (e) {
    if (typeof console !== "undefined") {
      Console.log(e, wbout);
    }
  }
  return wbout;
}

// 导出 到excel

// 用法：  exportExcel(表格绑定的id，文件名)
